﻿using System.Windows;

namespace FireUI.Core.TLManager;

public abstract class TLManageBase : ITLManager
{
    protected Dictionary<string, ResourceDictionary> _resources;

    public TLManageBase()
    {
        InitializeResources();
    }

    protected virtual void InitializeResources()
    { }

    public virtual void Apply(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return;
        }

        var key = _resources.Keys.FirstOrDefault(s => s.Equals(name, StringComparison.OrdinalIgnoreCase));
        if (key is null)
        {
            return;
        }

        foreach (var kvp in _resources)
        {
            Application.Current.Resources.MergedDictionaries.Remove(kvp.Value);
        }

        Application.Current.Resources.MergedDictionaries.Add(_resources[key]);
    }

    public virtual IEnumerable<string> GetNames() => _resources.Keys;
}